﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;


namespace mojoPortal.Web.RS.PRM.AppCode.Lib
{
    public class RSPRMDataLookupLoader : mojoPortal.Web.RS.AppCode.Lib.RSDataLookupLoader
    {
        public static void LoadPropertyOwnerDDL(int companyid, DropDownList ddlPropertyOwnerList, string itemIndexZeroText = "< Please select >", string itemIndexZeroValue = "0")
        {
            SqlCommand myCommand;
            SqlDataReader myDataReader;
            String sqlSELECT = "SELECT OwnerID, FirstName + ' ' + LastName AS OwnerName FROM rs_tblOwner WHERE CompanyID=@CompanyID ORDER BY FirstName, LastName ASC";
            SqlParameter param;
            SqlConnection myConnection;

            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[RSPRMCommonFunctions.GetRSCompanyConnectionString()].ToString());
            myCommand = new SqlCommand(sqlSELECT, myConnection);
            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@companyid";
            param.Value = companyid;
            myCommand.Parameters.Add(param);

            myConnection.Open();
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            ddlPropertyOwnerList.Items.Clear();
            ddlPropertyOwnerList.DataSource = myDataReader;
            ddlPropertyOwnerList.DataTextField = "OwnerName";
            ddlPropertyOwnerList.DataValueField = "OwnerID";
            ddlPropertyOwnerList.DataBind();
            ddlPropertyOwnerList.Items.Insert(0, new ListItem(itemIndexZeroText, itemIndexZeroValue));
            myConnection.Close();
        }
                
    }
}